package datastructure_algorithm.stack;

import datastructure_algorithm.array.Array;

public class ArrayStack<E> implements Stack<E> {

	private Array<E> array;

	public ArrayStack(int capacity) {
		array = new Array<>(capacity);
	}

	public ArrayStack() {
		array = new Array<>();
	}

	@Override
	public void push(E e) {
		array.addLast(e);
	}

	@Override
	public E pop() {
		return array.removeLast();
	}

	@Override
	public E peek() {
		return array.getLast();
	}

	@Override
	public int getSize() {
		return array.getSize();
	}

	@Override
	public boolean isEmpty() {
		return array.isEmpty();
	}

	public int getCapacity() {
		return array.getCapacity();
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("ArrayStack: top [");
		for (int i = getSize() - 1; i >= 0; i--) {
			sb.append(array.get(i));
			if (i != 0) {
				sb.append(", ");
			}
		}
		sb.append("]");
		return sb.toString();
	}

}
